package com.dirven.game;


import java.lang.Math;

public class Misc {
	
	/**
	 * Generates a random number between two values
	 */
	public static int randomNumber(int low, int high) {
		return (int) ((high - low +1 ) *Math.random() + low);
	}
	
	/**
	 * Generates a random number between two values
	 */
	public static double randomNumber(double low, double high) {
		return ((high - low +1 ) *Math.random() + low);
	}
	
	/**
	 * Chance method generates a true or false result based on the percent chance given.
	 * IE, if the percent given was 50%, then there is a 50% chance of the mthod returning
	 * true or false. Likewise if the chance given was 25%, then there would be a 25% chance
	 * of the method returning true.
	 */
	public static boolean randomChance(double percent) {
		
		if(percent > 100) {
			percent = 100;
			return true;
		} else if(percent < 0) {
			percent = 0;
			return false;
		}
		
		double divisor = 100 / percent;
		
		double rand = randomNumber(1, divisor);
		
		if(rand == 1.0) {
			return true;
		} else {
			return false;
		}
	}
		
}